package cn.yuemouren.leetcode;

/**
 * @Author: Timi
 * @Description: 345. 反转字符串中的元音字母
 *      元音字母:a e i o u
 * @Date: 2020/7/27 11:22
 */
public class Test_345 {

    public String reverseVowels(String s) {
        char[] charArray = s.toCharArray();
        int left = 0;
        int right = charArray.length - 1;
        String str = "aeiouAEIOU";
        while(left < right){
            boolean leftFlag = str.contains(charArray[left] + "");
            boolean rightFlag = str.contains(charArray[right] + "");
            if(leftFlag && !rightFlag){
                right--;
            } else if(!leftFlag && rightFlag){
                left++;
            } else if(!leftFlag && !rightFlag){
                left++;
                right--;
            } else {
                char c = charArray[left];
                charArray[left] = charArray[right];
                charArray[right] = c;
                left++;
                right--;
            }
        }
        return new String(charArray);
    }

    public static void main(String[] args) {
        String s = "leetcode";
        String pageUrl = new Test_345().reverseVowels(s);
        System.out.println(pageUrl);
    }
}
